package org.tote.dao;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.tote.model.MailMessageTemplate;
import org.tote.model.MailMessageType;

@Repository
public class MailMessageDaoImpl implements MailMessageDao {

	@Autowired
	private SessionFactory sessionFactory;
	
	@Override
    public void save(MailMessageTemplate mailMessage) {
	    sessionFactory.getCurrentSession().save(mailMessage);
    }

	@Override
    public void update(MailMessageTemplate mailMessage) {
		sessionFactory.getCurrentSession().merge(mailMessage);
    }

	@Override
    public void remove(MailMessageTemplate mailMessage) {
		sessionFactory.getCurrentSession().delete(mailMessage);
    }

	@Override
    public MailMessageTemplate getById(MailMessageType id) {
		MailMessageTemplate messageTemplate = (MailMessageTemplate)sessionFactory.getCurrentSession().get(MailMessageTemplate.class, id);
		// To disable Hibernate dirty check on this object
		sessionFactory.getCurrentSession().setReadOnly(messageTemplate, true);
		return messageTemplate;
    }

}